<template>
    <div class="income-template" v-bind:dataValue="showLoading">
        <yd-navbar slot="navbar" title="总收益" class="public-header">
            <span slot="left">
                <a href="javascript:window.history.go(-1)"><yd-navbar-back-icon></yd-navbar-back-icon></a>
            </span>
        </yd-navbar>
        <!--<yd-slider autoplay="3000">
            <yd-slider-item>
                <a href="http://www.ydcss.com">
                    <img src="http://static.ydcss.com/uploads/ydui/1.jpg">
                </a>
            </yd-slider-item>
            <yd-slider-item>
                <a href="http://www.ydcss.com">
                    <img src="http://static.ydcss.com/uploads/ydui/2.jpg">
                </a>
            </yd-slider-item>
            <yd-slider-item>
                <a href="http://www.ydcss.com">
                    <img src="http://static.ydcss.com/uploads/ydui/3.jpg">
                </a>
            </yd-slider-item>
        </yd-slider>-->
        <yd-grids-group :rows="2">
            <yd-grids-item>
                <div slot="text">
                    <div class="grids-icon">
                        <icon name="text-height" scale="1.5"></icon>
                    </div>
                    <p>投资总额 {{sumInvest}}元</p>
                </div>
            </yd-grids-item>
            <yd-grids-item>
                <div slot="text">
                    <div class="grids-icon">
                        <icon name="line-chart" scale="1.5"></icon>
                    </div>
                    <p>累计分红{{sumShare}}元</p>
                </div>
            </yd-grids-item>
        </yd-grids-group>
        <yd-cell-group title="收益统计">
            <yd-cell-item arrow v-for="item in list" @click.native="checkShowList(item)">
                <span slot="left"> {{item.shopName}}</span>
                <span slot="right">分红总额 {{item.share}}</span>
            </yd-cell-item>
        </yd-cell-group>
        <yd-popup v-model="showListDetail" position="right" width="70%">
            <yd-cell-item>
                <span slot="left"> {{listDetial.shopName}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">累计销售 {{listDetial.sumAmount}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">平均毛利润 {{listDetial.averagePercent}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">投资金额 {{listDetial.price}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">净利润 {{listDetial.netProfitAmount}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">可分配利润 {{listDetial.shareAmount}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">持股比例 {{listDetial.stock_right_percent}}%</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">分红总额 {{listDetial.share}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">店铺资产 {{listDetial.assets}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">投资回报周期 {{listDetial.paybackPeriod}}</span>
            </yd-cell-item>
            <yd-cell-item>
                <span slot="left">投资回报率 {{listDetial.paybackPercent}}%</span>
            </yd-cell-item>
        </yd-popup>
        <yd-tabbar slot="tabbar" class="public-footer">
            <yd-tabbar-item title="首页" link="/">
                <yd-icon name="home" slot="icon"></yd-icon>
            </yd-tabbar-item>
            <yd-tabbar-item title="投资收益" link="/income" active>
                <yd-icon name="shopcart-outline" slot="icon"></yd-icon>
            </yd-tabbar-item>
            <yd-tabbar-item title="信息交流" link="/message">
                <yd-icon name="like-outline" slot="icon"></yd-icon>
            </yd-tabbar-item>
            <yd-tabbar-item title="个人中心" link="/user">
                <yd-icon name="ucenter-outline" slot="icon"></yd-icon>
            </yd-tabbar-item>
        </yd-tabbar>
    </div>
</template>
<script>
    import Ajax from "../api/ajax.js";
    import dataURL from "../data/dataURL.js";
    export default {
        data() {
            return {
                page: 1,
                pageSize: 10,
                list: [
                    {
                        "user_id": 9,
                        "shop_id": 8, //店铺ID
                        "price": "20.00", //投资金额
                        "stock_right_percent": "20.00", //持股比例
                        "created_at": "1494236644", //
                        "updated_at": "1494236644",
                        "sumAmount": "0.00", //累计销售
                        "averagePercent": "0.000000", //平均毛利率
                        "netProfitAmount": "-4365.00", //净利润
                        "shareAmount": "-4365.00", // 可分配利润
                        "share": "-231.00", //分红总额
                        "shopName": "星奇异主题餐厅", //店铺名
                        "assets": 96384.84, //店铺总资产
                        "paybackPeriod": 0, //投资回报周期
                        "paybackPercent": 0// 投资回报率
                    }
                ],
                showListDetail: false,
                showStore: false,
                loadBloean: true,
                listDetial: {},
                sumInvest: "",//投资总额
                sumShare: "",//累积分红
            }
        },
        computed: {
            showLoading() {
                if (this.loadBloean) {
                    this.$dialog.loading.open('很快加载好了');
                } else {
                    this.$dialog.loading.close();
                }
            },
        },
        methods: {
            checkShowList(item) {
                this.showListDetail = true;
                this.listDetial = item;
            },
            async getData() {
                try {
                    let res = await Ajax.Post(dataURL.income.total);
                    this.list = res.data;
                    this.sumInvest = res.sumInvest;
                    this.sumShare = res.sumShare;
                    console.log(res);
                } catch (error) {
                    console.log("error")
                }
                this.loadBloean = false;
            }
        },
        mounted() {
            this.getData();
        }

    }

</script>